package com.jpush.gateway.config;

import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.ReactiveAuthenticationManager;
import org.springframework.security.web.server.authentication.AuthenticationWebFilter;
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers;

public class WebFluxLoginFilter extends AuthenticationWebFilter {
    public WebFluxLoginFilter(SpringSecurityTemplate template) {
        super(template.roleTxnManager());
        ServerWebExchangeMatcher loginMatcher = ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, "/login");
        this.setRequiresAuthenticationMatcher(loginMatcher);
        this.setServerAuthenticationConverter(template.loginConverter());
        this.setAuthenticationSuccessHandler(new WebFluxLoginSuccessHandler());
    }
}
